/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.bootstrap.jsf.bootstrap.component.output;

import java.io.IOException;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

/**
 *
 * @author alex
 */
@FacesComponent("toolTip")
public class ToolTip extends UIOutput {
    private String targetClass;
    private String id;
    private String orientation = "left";

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        setId(getClientId());
        
        if (getAttributes().containsKey("targetClass")) {
            setTargetClass(getAttributes().get("targetClass").toString());
        }
        
        if (getAttributes().containsKey("orientation")) {
            setOrientation(getAttributes().get("orientation").toString());
        }
        
        ResponseWriter rw = context.getResponseWriter();

        rw.startElement("script", this);
        rw.writeAttribute("type", "text/javascript", "type");
        rw.write("toolTip('"+getTargetClass()+"' , '" +getOrientation()+ "' , '" +getValue().toString()+ "')");
        
    }

    @Override
    public void encodeEnd(FacesContext context) throws IOException {
        ResponseWriter rw = context.getResponseWriter();
        rw.endElement("script");
    }
    
    
    
    /**
     * @return the targetClass
     */
    public String getTargetClass() {
        return targetClass;
    }

    /**
     * @param targetClass the targetClass to set
     */
    public void setTargetClass(String targetClass) {
        this.targetClass = targetClass;
    }

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return the orientation
     */
    public String getOrientation() {
        return orientation;
    }

    /**
     * @param orientation the orientation to set
     */
    public void setOrientation(String orientation) {
        this.orientation = orientation;
    }
    
    
}
